package org.hhchat.leetcode.array;

/**
 * Created this one by HMH on 2017/10/3.
 */
public class code566_easy {

    static class Solution {
        public int[][] matrixReshape(int[][] nums, int r, int c) {
            int count = nums.length * nums[0].length;
            if (count != r * c) {
                return nums;
            }

            int[][] newNums = new int[r][c];
            for(int j = 0 ; j<nums.length;j++) {
                for (int i = 0; i < nums[0].length; i++) {
                    add(newNums, nums[j][i]);
                }
            }
            return newNums;
        }

        int x = 0;
        int y = 0;

        public void add(int[][] nums,int val) {
            nums[y][x] = val;
            x++;
            y++;
            if (y >= nums.length - 1) {
                y = 0;
            }
            if (x >= nums[0].length - 1) {
                x = 0;
            }
        }
    }

    public static void main(String[] args){

    }
}
